﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceModel;
using Insteon;
using Interfaces;
using Scheduling;

namespace Mesne
{
    [ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single)]
    public class ServiceProxy : IServiceContract
    {
        public void SendMessage(ICommand command)
        {
            Server.Instance.SendMessage(command);
        }

        public bool EstablishCallback()
        {
            bool result = false;
            var currentSessionCallback = OperationContext.Current.GetCallbackChannel<IClientCallback>();
            if(currentSessionCallback != null)
            {
                result = Server.Instance.EstablishCallback(OperationContext.Current.SessionId, currentSessionCallback);
            }
            return result;
        }

        public void Disconnect()
        {
            Server.Instance.RemoveCallback(OperationContext.Current.SessionId);
        }

        public string GetConfig()
        {
           return Server.Instance.GetConfig();
        }
        
        public bool ScheduleOperation(IOperation operation)
        {
            return Server.Instance.ScheduleOperation(operation);
        }

        public List<IDevice> GetDevices()
        {
            return Server.Instance.GetDevices(OperationContext.Current.SessionId);
        }

        public bool ScheduleOperations(List<IOperation> operation)
        {
            return Server.Instance.ScheduleOperations(operation);
        }

        public List<IOperation> GetOperations()
        {
            return Server.Instance.GetOperations();
        }

        public bool DeleteOperation(string name)
        {
            return Server.Instance.DeleteOperation(name);
        }

        public bool DeleteOperations(List<string> names)
        {
            return Server.Instance.DeleteOperations(names);
        }

        public bool DeleteAllOperations()
        {
            return Server.Instance.DeleteAllOperations();
        }
    }
}
